(function () {
    var _cloudBase = {
        timer: 0,
        cloudId: "san_cloud",
        cloudIndexName: 'wechat-index',
        cloudImage: "travel.jiafen520.com",
        cloudWechat: null,
        companyId: null,
        content: null,
        domain: null,
        pm:{},
        getCode: function () {
            var signCacheName = this.getCacheName('sign_');
            return this.getCache(signCacheName);
        },
        getBdVid: function () {
            var _href = this.getHref();
            if (!_href) {
                return "";
            }
            if (_href.indexOf("bd_vid") == -1) {
                return "";
            }
            return this.parseQueryParams(_href, "bd_vid");
        },
        getPages: function () {
            var result, body = document.getElementsByTagName("body");
            if (body) {
                if (body.length > 0) {
                    result = body[0].getAttribute("data-pages");
                }
            }
            return result || 2;
        },
        getWidth: function () {
            var e = document;
            return parseInt(window.innerWidth || e.documentElement.clientWidth || e.body.offsetWidth || 0, 10);
        },
        getHeight: function () {
            var e = document;
            return parseInt(window.innerHeight || e.documentElement.clientHeight || e.body && e.body.clientHeight || 0, 10);
        },
        getDevice:function(){
             var userAgent = this.getUserAgent();
              var agent = userAgent.toLowerCase(), iphone = 'iphone', android = 'android';
            //判断是否是手机
                if (agent.indexOf(iphone) > -1) {
                    return 'iOS' ;
                }
                if (agent.indexOf(android) > -1) {
                    return 'Android';
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux';
                }
                return 'PC' ;
        },
        getDeviceName: function () {
            var userAgent = this.getUserAgent();
            if (!userAgent) {
                return 'other';
            }
            var agent = userAgent.toLowerCase(), iphone = 'iphone', android = 'android',
                iphoneName = '苹果', androidName = '安卓', browserName = '';
                console.log(agent);
            if (agent.indexOf('windowswechat') > -1) {
                return '微信PC浏览器';
            }
            if (agent.indexOf('fxios') > -1) {
                browserName = 'Firefox浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('mxios') > -1) {
                browserName = '傲游浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('mb2345browser') > -1) {
                browserName = '2345浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('newsarticle') > -1) {
                browserName = '今日头条APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('com.hydx') > -1) {
                browserName = 'ViaX浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('crios') > -1) {
                browserName = '谷歌APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('qhbrowser') > -1) {
                browserName = '360浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('micromessenger') > -1) {
                browserName = '微信';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('mqqbrowser') > -1) {
                browserName = 'QQ浏览器';
                if (agent.indexOf('qqtheme') > -1) {
                    browserName = 'QQ内置浏览器';
                }
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('baiduboxapp') > -1) {
                browserName = '百度APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('sogousearch') > -1) {
                browserName = '搜狗搜索APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('weibo') > -1) {
                browserName = '微博';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('live_stream') > -1) {
                browserName = '火山视频';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('videoarticle') > -1) {
                browserName = '西瓜视频';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('bytelocale') > -1) {
                browserName = '抖音APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('sogoumobilebrowser') > -1) {
                browserName = '搜狗浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('mso_app') > -1) {
                browserName = '360搜索APP';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('ucbrowser') > -1) {
                browserName = 'UC浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('fingerbrowser') > -1) {
                browserName = '高速浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('quark') > -1) {
                browserName = '夸克浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('edgios') > -1) {
                browserName = 'Edgios浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('gear') > -1) {
                browserName = 'Gear浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('hongyun') > -1) {
                browserName = '红云浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('hao123') > -1) {
                browserName = '好123浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('tlbrowser') > -1) {
                browserName = '淘搜浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('mybrowser') > -1) {
                browserName = '大白鲨浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('safebrowser') > -1) {
                browserName = '安全浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf('yayabrowser') > -1) {
                browserName = '鸭鸭浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                return browserName;
            }
         //判断是否Opera浏览器
            if (agent.indexOf("Opera") > -1 || agent.indexOf("opera") > -1) {
                browserName = '欧朋浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            };

            //判断是否Edge浏览器
            if (agent.indexOf("Edg") > -1 || agent.indexOf("edg") > -1) {
                browserName = 'Edge浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            }

            //判断是否Firefox浏览器
            if (agent.indexOf("Firefox") > -1 || agent.indexOf("firefox") > -1) {
                browserName = '火狐浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            }

            //判断是否Chrome浏览器
            if (agent.indexOf("Chrome") > -1 || agent.indexOf("chrome") > -1) {
                browserName = '谷歌浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            }

            //判断是否Safari浏览器
            if ((agent.indexOf("Safari") > -1 || agent.indexOf("safari") > -1 )&& agent.indexOf("chrome") < 0) {
                browserName = 'Safari浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            }

            //判断是否IE浏览器
            if (agent.indexOf("compatible") > -1 && agent.indexOf("MSIE") > -1) {
                browserName = 'IE浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;
            }
            if (agent.indexOf("Trident") > -1 || agent.indexOf("trident") > -1) {
                browserName = 'IE浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;

            }
            if (agent.indexOf("Huaweioem") > -1 || agent.indexOf("huaweioem") > -1) {
                browserName = '华为浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;

            }
             if (agent.indexOf("Aweme") > -1 || agent.indexOf("aweme") > -1) {
                browserName = '抖音';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;

            }
             if (agent.indexOf("Aweme") > -1 || agent.indexOf("aweme") > -1) {
                browserName = '抖音';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;

            }
             if (agent.indexOf("Netscape") > -1 || agent.indexOf("netscape") > -1) {
                browserName = 'Netscape浏览器';
                if (agent.indexOf(iphone) > -1) {
                    return iphoneName + '' + browserName;
                }
                if (agent.indexOf(android) > -1) {
                    return androidName + '' + browserName;
                }
                if (agent.indexOf('windows') > -1) {
                    return 'Windows' + '' + browserName;
                }
                if (agent.indexOf('linux') > -1) {
                    return 'Linux' + '' + browserName;
                }
                return browserName;

            }
            if (agent.indexOf('windows') > -1) {
                return 'Windows';
            }
            if (agent.indexOf('linux') > -1) {
                return 'Linux';
            }
            return 'other';
        },
        getHref: function () {
            var href = '';
            try {
                href = window.parent.location.href;
            } catch (e) {
                href = window.location.href;
            }
            return href;
        },
        parseQueryParams: function (url, pa) {
            if (!url) {
                return "";
            }
            if (!pa) {
                return "";
            }
            url = url.replace(/#+.*$/, "");
            if (url.indexOf(pa + "=") == -1) {
                return "";
            }
            var params = url.substring(url.indexOf("?") + 1, url.length).split("&"), param = {};
            for (var i = 0; i < params.length; i++) {
                var pos = params[i].indexOf("="), key = params[i].substring(0, pos), val = params[i].substring(pos + 1);
                param[key] = val
            }
            if (this.getParamType(param[pa]) === 'undefined') {
                return "";
            }
            return param[pa];
        },
        getParamType: function (obj) {
            return obj == null ? String(obj) : Object.prototype.toString.call(obj).replace(/\[object\s+(\w+)\]/i, "$1") || "object"
        },
        getUserAgent: function () {
            var userAgent = '';
            try {
                userAgent = navigator.userAgent;
                ;
            } catch (e) {
                userAgent = window.navigator.userAgent;
            }
            return userAgent;
        },
        getLanguage: function () {
            var language = '';
            try {
                language = navigator.language || navigator.browserLanguage || navigator.systemLanguage || navigator.userLanguage || "";
            } catch (e) {
                language = window.navigator.language || window.navigator.browserLanguage || window.navigator.systemLanguage || window.navigator.userLanguage || "";
            }
            return language;
        },
        getPlatform: function () {
            var platform = '';
            try {
                platform = navigator.platform;
                ;
            } catch (e) {
                platform = window.navigator.platform;
            }
            return platform;
        },
        getColorDepth: function () {
            var colorDepth = '';
            try {
                colorDepth = window.screen.colorDepth || 0;
            } catch (e) {
                colorDepth = 0;
            }
            return colorDepth
        },
        getWord: function () {
            var _referrer = this.getReferrer();
            if (!_referrer) {
                return "";
            }
            if (_referrer.indexOf("?") == -1) {
                return "";
            }
            var result = "";
            if (_referrer.indexOf(".baidu.com/") > -1) {
                result = this.parseQueryParams(_referrer, "wd");
                if (result) {
                    return result;
                }
                return this.parseQueryParams(_referrer, "word");
            }
            if (_referrer.indexOf(".sogou.com/") > -1) {
                result = this.parseQueryParams(_referrer, "query");
                if (result) {
                    return result;
                }
                return this.parseQueryParams(_referrer, "keyword");
            }
            if (_referrer.indexOf(".sm.cn/") > -1) {
                return this.parseQueryParams(_referrer, "q");
            }
            if (_referrer.indexOf(".so.com/") > -1) {
                return this.parseQueryParams(_referrer, "q");
            }
            return result;
        },
        getReferrer: function () {
            var referrer = '';
            try {
                referrer = window.parent.document.referrer;
            } catch (e) {
                referrer = document.referrer;
            }
            return referrer;
        },
        getKeywordId: function () {
            var _href = this.getHref(), keywordld = 'e_keywordld';
            if (!_href) {
                return "";
            }
            if (_href.indexOf(keywordld) == -1) {
                return "";
            }
            return this.parseQueryParams(_href, keywordld);
        },
        getOffset: function () {
            var e = document;
            return parseInt(window.pageYOffset || e.documentElement.scrollTop || e.body && e.body.scrollTop || 0, 10);
        },
        httpClient: function (method, url, param, result) {
            var xhr = new XMLHttpRequest();
            xhr.open(method, method == "POST" ? url + '?t=' + new Date().getTime() : url + '?t=' + new Date().getTime() + '&' + param, true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status == 200) {
                        var response = xhr.responseText || xhr.response;
                        result(response);
                    } else {
                        result(false);
                    }
                }
            };
            xhr.send(method == "POST" ? param : null);
        },
        setCache: function (sName, sValue, iExpireSec, sDomain, sPath, bSecure) {
            if (sName == undefined) {
                return this;
            }
            if (sValue == undefined) {
                sValue = ""
            }
            if (window.localStorage) {
                localStorage.setItem(sName, sValue);
                return this;
            }
            var oCookieArray = [sName + "=" + encodeURIComponent(sValue)];
            if (this.getParamType(iExpireSec).toLowerCase() === "number" && !isNaN(iExpireSec)) {
                var oDate = new Date;
                oDate.setTime(oDate.getTime() + iExpireSec * 1e3);
                iExpireSec == 0 ? "" : oCookieArray.push("expires=" + oDate.toGMTString())
            }
            if (sDomain != undefined) {
                oCookieArray.push("domain=" + sDomain)
            }
            if (sPath != undefined) {
                oCookieArray.push("path=" + sPath)
            }
            if (bSecure) {
                oCookieArray.push("secure")
            }
            document.cookie = oCookieArray.join("; ")
            return this;
        },
        getCache: function (sName, sDefaultValue) {
            if (window.localStorage) {
                return localStorage.getItem(sName);
            }
            var sRE = "(?:; |^)" + sName + "=([^;]*);?";
            var oRE = new RegExp(sRE);
            if (oRE.test(document.cookie)) {
                return decodeURIComponent(RegExp["$1"])
            }
            return sDefaultValue || null
        },
        binl2rstr: function (input) {
            var i
            var output = ''
            var length32 = input.length * 32
            for (i = 0; i < length32; i += 8) {
                output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff)
            }
            return output
        },

        bitRotateLeft: function (num, cnt) {
            return (num << cnt) | (num >>> (32 - cnt))
        },

        safeAdd: function (x, y) {
            var lsw = (x & 0xffff) + (y & 0xffff)
            var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
            return (msw << 16) | (lsw & 0xffff)
        },

        codecmn: function (q, a, b, x, s, t) {
            return this.safeAdd(this.bitRotateLeft(this.safeAdd(this.safeAdd(a, q), this.safeAdd(x, t)), s), b)
        },

        codegg: function (a, b, c, d, x, s, t) {
            return this.codecmn((b & d) | (c & ~d), a, b, x, s, t)
        },

        codehh: function (a, b, c, d, x, s, t) {
            return this.codecmn(b ^ c ^ d, a, b, x, s, t)
        },

        codeii: function (a, b, c, d, x, s, t) {
            return this.codecmn(c ^ (b | ~d), a, b, x, s, t)
        },

        codeff: function (a, b, c, d, x, s, t) {
            return this.codecmn((b & c) | (~b & d), a, b, x, s, t)
        },

        binlcode: function (x, len) {
            x[len >> 5] |= 0x80 << len % 32;
            x[(((len + 64) >>> 9) << 4) + 14] = len;
            var i;
            var olda;
            var oldb;
            var oldc;
            var oldd;
            var a = 1732584193;
            var b = -271733879;
            var c = -1732584194;
            var d = 271733878;
            for (i = 0; i < x.length; i += 16) {
                olda = a
                oldb = b
                oldc = c
                oldd = d
                a = this.codeff(a, b, c, d, x[i], 7, -680876936);
                d = this.codeff(d, a, b, c, x[i + 1], 12, -389564586);
                c = this.codeff(c, d, a, b, x[i + 2], 17, 606105819);
                b = this.codeff(b, c, d, a, x[i + 3], 22, -1044525330);
                a = this.codeff(a, b, c, d, x[i + 4], 7, -176418897);
                d = this.codeff(d, a, b, c, x[i + 5], 12, 1200080426);
                c = this.codeff(c, d, a, b, x[i + 6], 17, -1473231341);
                b = this.codeff(b, c, d, a, x[i + 7], 22, -45705983);
                a = this.codeff(a, b, c, d, x[i + 8], 7, 1770035416);
                d = this.codeff(d, a, b, c, x[i + 9], 12, -1958414417);
                c = this.codeff(c, d, a, b, x[i + 10], 17, -42063);
                b = this.codeff(b, c, d, a, x[i + 11], 22, -1990404162);
                a = this.codeff(a, b, c, d, x[i + 12], 7, 1804603682);
                d = this.codeff(d, a, b, c, x[i + 13], 12, -40341101);
                c = this.codeff(c, d, a, b, x[i + 14], 17, -1502002290);
                b = this.codeff(b, c, d, a, x[i + 15], 22, 1236535329);
                a = this.codegg(a, b, c, d, x[i + 1], 5, -165796510);
                d = this.codegg(d, a, b, c, x[i + 6], 9, -1069501632);
                c = this.codegg(c, d, a, b, x[i + 11], 14, 643717713);
                b = this.codegg(b, c, d, a, x[i], 20, -373897302);
                a = this.codegg(a, b, c, d, x[i + 5], 5, -701558691);
                d = this.codegg(d, a, b, c, x[i + 10], 9, 38016083);
                c = this.codegg(c, d, a, b, x[i + 15], 14, -660478335);
                b = this.codegg(b, c, d, a, x[i + 4], 20, -405537848);
                a = this.codegg(a, b, c, d, x[i + 9], 5, 568446438);
                d = this.codegg(d, a, b, c, x[i + 14], 9, -1019803690);
                c = this.codegg(c, d, a, b, x[i + 3], 14, -187363961);
                b = this.codegg(b, c, d, a, x[i + 8], 20, 1163531501);
                a = this.codegg(a, b, c, d, x[i + 13], 5, -1444681467);
                d = this.codegg(d, a, b, c, x[i + 2], 9, -51403784);
                c = this.codegg(c, d, a, b, x[i + 7], 14, 1735328473);
                b = this.codegg(b, c, d, a, x[i + 12], 20, -1926607734);
                a = this.codehh(a, b, c, d, x[i + 5], 4, -378558);
                d = this.codehh(d, a, b, c, x[i + 8], 11, -2022574463);
                c = this.codehh(c, d, a, b, x[i + 11], 16, 1839030562);
                b = this.codehh(b, c, d, a, x[i + 14], 23, -35309556);
                a = this.codehh(a, b, c, d, x[i + 1], 4, -1530992060);
                d = this.codehh(d, a, b, c, x[i + 4], 11, 1272893353);
                c = this.codehh(c, d, a, b, x[i + 7], 16, -155497632);
                b = this.codehh(b, c, d, a, x[i + 10], 23, -1094730640);
                a = this.codehh(a, b, c, d, x[i + 13], 4, 681279174);
                d = this.codehh(d, a, b, c, x[i], 11, -358537222);
                c = this.codehh(c, d, a, b, x[i + 3], 16, -722521979);
                b = this.codehh(b, c, d, a, x[i + 6], 23, 76029189);
                a = this.codehh(a, b, c, d, x[i + 9], 4, -640364487);
                d = this.codehh(d, a, b, c, x[i + 12], 11, -421815835);
                c = this.codehh(c, d, a, b, x[i + 15], 16, 530742520);
                b = this.codehh(b, c, d, a, x[i + 2], 23, -995338651);
                a = this.codeii(a, b, c, d, x[i], 6, -198630844);
                d = this.codeii(d, a, b, c, x[i + 7], 10, 1126891415);
                c = this.codeii(c, d, a, b, x[i + 14], 15, -1416354905);
                b = this.codeii(b, c, d, a, x[i + 5], 21, -57434055);
                a = this.codeii(a, b, c, d, x[i + 12], 6, 1700485571);
                d = this.codeii(d, a, b, c, x[i + 3], 10, -1894986606);
                c = this.codeii(c, d, a, b, x[i + 10], 15, -1051523);
                b = this.codeii(b, c, d, a, x[i + 1], 21, -2054922799);
                a = this.codeii(a, b, c, d, x[i + 8], 6, 1873313359);
                d = this.codeii(d, a, b, c, x[i + 15], 10, -30611744);
                c = this.codeii(c, d, a, b, x[i + 6], 15, -1560198380);
                b = this.codeii(b, c, d, a, x[i + 13], 21, 1309151649);
                a = this.codeii(a, b, c, d, x[i + 4], 6, -145523070);
                d = this.codeii(d, a, b, c, x[i + 11], 10, -1120210379);
                c = this.codeii(c, d, a, b, x[i + 2], 15, 718787259);
                b = this.codeii(b, c, d, a, x[i + 9], 21, -343485551);
                a = this.safeAdd(a, olda);
                b = this.safeAdd(b, oldb);
                c = this.safeAdd(c, oldc);
                d = this.safeAdd(d, oldd);
            }
            return [a, b, c, d]
        },

        rstr2binl: function (input) {
            var i
            var output = []
            output[(input.length >> 2) - 1] = undefined
            for (i = 0; i < output.length; i += 1) {
                output[i] = 0
            }
            var length8 = input.length * 8
            for (i = 0; i < length8; i += 8) {
                output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32
            }
            return output
        },

        str2rstrUTF8: function (input) {
            return unescape(encodeURIComponent(input))
        },

        rstrcode: function (s) {
            return this.binl2rstr(this.binlcode(this.rstr2binl(s), s.length * 8))
        },

        str2rstrUTF8: function (input) {
            return unescape(encodeURIComponent(input))
        },

        rawcode: function (s) {
            return this.rstrcode(this.str2rstrUTF8(s))
        },

        rstr2hex: function (input) {
            var hexTab = '0123456789abcdef'
            var output = ''
            var x
            var i
            for (i = 0; i < input.length; i += 1) {
                x = input.charCodeAt(i)
                output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f)
            }
            return output
        },

        getCacheName: function (name) {
            var url = this.getHref(), protocol = 'https://';
            if (url.indexOf(protocol) > -1) {
                url = url.replace(protocol, "");
            }
            protocol = 'http://';
            if (url.indexOf(protocol) > -1) {
                url = url.replace(protocol, "");
            }
            protocol = '?';
            if (url.indexOf(protocol) > -1) {
                url = url.split(protocol)[0];
            }
            var cacheName = this.rstr2hex(this.rawcode(url));
            if (name) {
                return 'hm_cloud_' + name + cacheName;
            }
            return cacheName;
        },

        isDataLegal: function (param) {
            if (!param) {
                return false;
            }
            var obj = JSON.parse(param);
            if (!obj) {
                return false;
            }
            if (!obj.hasOwnProperty('code')) {
                return false;
            }
            if (obj.code != 0) {
                return false;
            }
            if (!obj.hasOwnProperty('data')) {
                return false;
            }
            if (!obj.hasOwnProperty('sign')) {
                return false;
            }
            if (!obj.data.hasOwnProperty('wechat')) {
                return false;
            }
            if (!obj.data.hasOwnProperty('company')) {
                return false;
            }
            return obj;
        },

        setWechatData: function (obj) {
            this.cloudWechat = obj.wechat;
            that=this;
            var wechat = document.getElementsByClassName("app_wechat");
            if (wechat) {
                for (var i = 0; i < wechat.length; i++) {
                    wechat[i].innerHTML = obj.wechat;
                    wechat[i].setAttribute(this.cloudIndexName, i + 1);
                    wechat[i].addEventListener('copy', function(e) {
                        console.log(that.pm);
                            that.setListenerCopy(that.pm);
                    });	
                    // wechat[i].addEventListener('paste', function() {
                    //     console.log('122');
                    //         this.setListenerCopy(this.pm);
                    // });	
                    wechat[i].addEventListener('cut', function() {
                        console.log('112');
                            this.setListenerCopy(this.pm);
                    });

                }
            }
            var sex = document.getElementsByClassName("app_sex");
            if (sex) {
                for (var i = 0; i < sex.length; i++) {
                    sex[i].innerHTML = (obj.sex ? '他' : '她');
                }
            }
            var name = document.getElementsByClassName("app_name");
            if (name) {
                for (var i = 0; i < name.length; i++) {
                    name[i].innerHTML = obj.name;
                }
            }
            var phone = document.getElementsByClassName("app_phone");
            if (phone) {
                for (var i = 0; i < phone.length; i++) {
                    phone[i].innerHTML = obj.phone;
                }
            }
            var company = document.getElementsByClassName("app_company");
            if (company) {
                for (var i = 0; i < company.length; i++) {
                    company[i].innerHTML = obj.company;
                }
            }

            var qrcode = document.getElementsByClassName("app_qrcode");
            if (qrcode) {
                for (var i = 0; i < qrcode.length; i++) {
                    qrcode[i].src = obj.qrcode;
                }
                var qrcode_view = document.getElementsByClassName("app_qrcode_view");
                if (qrcode_view) {
                    var qrcodeDiv = document.createElement("div");
                    if (qrcodeDiv) {
                        qrcodeDiv.id = "qrcode_view_event"
                        qrcodeDiv.innerHTML = '<div class="wechat_window" style="width:238px;height:271px;position:fixed;top:50%;margin-top:-120px;left:50%;margin-left:-120px;z-index:9999;background:url(http://' + this.cloudImage + '/qr/31715ae698d9b553c742bf2b80c2728197506d12.png) no-repeat;"> <div style="width:175px;height:175px;margin:40px 0 0 26px;line-height:175px;text-align:center;font-size:0;box-sizing:border-box;"><img src="' + obj.qrcode + '" style="max-width:175px;height:auto;vertical-align:middle;"> </div> <div style="width:35px;height:35px;position:absolute;top:0;right:0;cursor:pointer;" id="wechat_window_close"></div></div><div style="position:fixed;top:0;left:0;right:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:8888;cursor:pointer;"></div>';
                        for (var i = 0; i < qrcode_view.length; i++) {
                            qrcode_view[i].onclick = function () {
                                document.body.appendChild(qrcodeDiv);
                                var wechatClose = document.getElementById("wechat_window_close");
                                if (wechatClose) {
                                    wechatClose.onclick = function (t) {
                                        var qrcode_remove = document.getElementById("qrcode_view_event");
                                        if (qrcode_remove) {
                                            qrcode_remove.remove()
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },

        httpClientRetry: function (wechatName, signName, param) {
            var that = this, retryCount = 0, intervalId = setInterval(function () {
                that.httpClient("GET", that.domain + "/getData", param + '&timer=' + that.timer + '&offset=' + that.getOffset(), function (response) {
                    retryCount++;
                    if (response) {
                        var result = that.isDataLegal(response);
                        if (result) {
                            that.setCache(signName, result.sign).setCache(wechatName, response);
                            that.setWechatData(result.data);
                            clearInterval(intervalId);
                        }
                    }
                    if (retryCount == 10) {
                        clearInterval(intervalId);
                    }
                });
            }, 200);
        },

        getWecatData: function (param) {
            var that = this, wechatCacheName = this.getCacheName('wechat_'), signCacheName = this.getCacheName('sign_'),
                wechat = this.getCache(wechatCacheName);
            var result = that.isDataLegal(wechat);
            if (result) {
                that.setWechatData(result.data);
                return;
            }
            that.httpClient("GET", that.domain + "/getData", param + '&timer=' + that.timer + '&offset=' + that.getOffset(), function (response) {
                if (!response) {
                    that.httpClientRetry(wechatCacheName, signCacheName, param);
                    return;
                }
                var result = that.isDataLegal(response);
                if (!result) {
                    that.httpClientRetry(wechatCacheName, signCacheName, param);
                    return;
                }
                that.setCache(signCacheName, result.sign).setCache(wechatCacheName, response);
                that.setWechatData(result.data);
            });
        },

        trimContent: function (str) {
            if (!str) {
                return '';
            }
            str = str.replace(/\s+/g, "");
            str = str.replace(/\n|\r/g, "");
            return encodeURIComponent(str);
        },

        getIndex: function (e) {
            var t = null;
            try {
                t = e.baseNode.nextSibling.getAttribute(this.cloudIndexName)
            } catch (e) {
            }
            if (t) return t;
            try {
                t = e.baseNode.previousSibling.getAttribute(this.cloudIndexName)
            } catch (e) {
            }
            if (t) return t;
            try {
                t = e.baseNode.parentElement.getAttribute(this.cloudIndexName)
            } catch (e) {
            }
            if (t) return t;
            try {
                t = e.extentNode.parentNode.getAttribute(this.cloudIndexName)
            } catch (e) {
            }
            if (t) return t;
            try {
                t = e.anchorNode.parentNode.nextElementSibling.lastChild.getAttribute(this.cloudIndexName)
            } catch (e) {
            }
            if (t) return t;
            try {
                var nextElementSibling = e.baseNode.nextElementSibling.childNodes;
                if (nextElementSibling.length > 0) {
                    t = nextElementSibling[0].getAttribute(this.cloudIndexName);
                }
            } catch (e) {
            }
            if (t) return t;
            try {
                var previousSibling = e.anchorNode.previousSibling.childNodes;
                if (previousSibling.length > 0) {
                    t = previousSibling[0].getAttribute(this.cloudIndexName);
                }
            } catch (e) {
            }
            if (t) return t;
            try {
                var previousElementSibling = e.extentNode.previousElementSibling.childNodes;
                if (previousElementSibling.length > 0) {
                    t = previousElementSibling[0].getAttribute(this.cloudIndexName);
                }
            } catch (e) {
            }
            return t || t || -1
        },

        createImg: function (param) {
            var _createImg = document.createElement("img");
            if (_createImg) {
                _createImg.src = param;
            }
        },

        setListenerCopy: function (param) {
            var that = this, timerName = this.getCacheName('timer_');
            try {
                setInterval(function () {
                    that.timer = that.getCache(timerName);
                    if (!that.timer) {
                        that.timer = 0;
                    }
                    that.timer = parseInt(that.timer);
                    that.timer += 1;
                    var selection = window.getSelection(0);
                    if (!selection) {
                        selection = window.getSelection();
                    }
                    that.setCache(timerName, that.timer).setListenerOnline(param);
                    var _content = selection.toString(), index = that.getIndex(selection);
                    if (_content && _content.indexOf(that.cloudWechat) > -1) {
                        if (that.content !== _content) {
                            that.content = _content;
                            that.httpClient("POST", that.domain + "/setData", param + '&content=' + that.trimContent(_content) + '&wechat=' + that.cloudWechat + '&index=' + index + '&code=' + that.getCode() + '&timer='
                                + that.timer + '&offset=' + that.getOffset(), function (response) {
                                if (!response) {
                                    that.createImg(that.domain + '/setData?t=' + new Date().getTime() + '&' + param + '&content=' + that.trimContent(_content) + '&wechat=' + that.cloudWechat + '&index=' + index + '&code=' + that.getCode() + '&timer='
                                        + that.timer + '&offset=' + that.getOffset());
                                }
                            });
                        }
                    }
                }, 1e3);
            } catch (e) {
            }
        },

        setListenerOnline: function (param) {
            var code = this.getCode();
            if (code) {
                this.createImg(this.domain + '/setOnline?t=' + new Date().getTime() + '&' + param + '&code=' + code + '&timer=' + this.timer + '&offset=' + this.getOffset());
            }
        },

        setListenerComment() {
            var that = this, comment = document.getElementById("app_comment");
            if (comment) {
                var innerHTML = '<style>.ct_mm_tourist .ct_mm_answer{ text-align: left; padding-left:10px; margin-bottom:10px} .ct_mm_tourist .ct_mm_answer .ct_mm_item{ padding:0px 12px 10px;border-bottom:1px solid #dbdbdb;background:#FFF} .ct_mm_tourist .ct_mm_answer .ct_mm_item .ct_mm_img{ float:left; width:32px;height:32px;margin-right:8px} .ct_mm_tourist .ct_mm_answer .ct_mm_item .ct_mm_plas{ color:#111; font-size:14px;font-style:normal;font-weight:normal} .ct_mm_tourist .ct_mm_answer .ct_mm_item .ct_mm_plas .ct_mm_em{padding:0 .2rem; border-radius:.3rem;color:#ff9d00;margin-left:3px;font-size:12px;font-style:normal;font-weight:normal} .ct_mm_tourist .ct_mm_answer .ct_mm_item .ct_mm_con{color:#696969;max-height:800px;overflow:hidden;text-overflow:ellipsis;margin:10px 0} .ct_mm_tourist .ct_mm_answer .ct_mm_btns {margin:2px 0 8px 0;padding:0} .ct_mm_tourist .ct_mm_answer .ct_mm_btns .ct_mm_hnum{font-weight:normal;font-style:normal;font-size:14px;color:#ff8a00} .ct_mm_tourist .ct_mm_answer .ct_mm_btns .ct_mm_btn1 span{font-size:14px} .ct_mm_tourist .ct_mm_answer .ct_mm_btns .ct_mm_btn1 i{display:inline-block;margin:0 5px 1px 0;width:37px;height:33px;background:url(https://' + that.cloudImage + '/43e0bbcc83f8b8c8ad9a6096f41c92e2.png) no-repeat;background-position:3px -36px;background-size:101px;vertical-align:middle} .ct_mm_tourist .ct_mm_answer .ct_mm_uide{ margin-top:6px; height:30px; display:inline-block;padding:3px 6px;height:9px;border-radius:8px;background-color:#70c2b9;color:#fff;line-height:8px;font-size:8px} .ct_mm_tourist .ct_mm_answer .ct_mm_uide:before{height:30px; display:inline-block;margin:0 2px 2px 0;width:11px;height:9px;background:url(https://' + that.cloudImage + '/7863d22306628170900cc8b52bf18d11.png) no-repeat;background-position:-20px 0;vertical-align:middle;background-size:50px;content:""} .ct_mm_tourist .ct_mm_answer .ct_mm_p{font-size:14px;font-style:normal;font-weight:normal;word-wrap:break-word} .ct_mm_tourist .ct_mm_answer .ct_mm_hoard{cursor:pointer} .ct_mm_tourist .issue>textarea{ width:99%; resize:none; border-radius:5px;-webkit-appearance:none;border:1px solid #09f;padding:5px 4px;font-size:12px;overflow:auto;height:100px;outline:0} .ct_mm_tourist .issue>div{text-align:right;margin-top:10px;margin-right:5px} .ct_mm_tourist .issue>div>button:hover{background-color:green} .ct_mm_tourist .issue>div>button{padding:5px 20px;background-color:#ff9d00;-webkit-appearance:none;outline:0;border-radius:3px;border:0;color:white;cursor:pointer}</style> <div class="ct_mm_tourist"><div class="ct_mm_answer" id="ct_mm_answer"></div><div class="issue"><textarea id="txt1" placeholder="请输入要评论的内容." style="padding: 5px;"></textarea><div><button id="publish">发表</button></div></div></div>',
                    create = document.createElement("div");
                create.innerHTML = innerHTML, comment.appendChild(create);
                var localCommentCacheName = that.getCacheName('comment_'), loadComment = function () {
                    var t = that.getCache(localCommentCacheName);
                    if (t && (comment = t.split("{$0}"), 3 == comment.length)) {
                        document.getElementById("ct_mm_answer").innerHTML = '​<div class="ct_mm_item"><div class="ct_mm_img"><img src="https://' + that.cloudImage + '/1bb45c6188973ccd8d8ce36710c7646c.jpg" style="width: 32px; height: 32px;"></div><div class="ct_mm_plas"> <div class="ct_mm_em"> LV.0</div></div><span class="ct_mm_uide">游客</span><div class="ct_mm_con"> <p class="ct_mm_p">' + comment[0] + 'aa</p> </div> <div class="ct_mm_btns"> <a class="ct_mm_btn1"> <i class="ct_mm_hoard"></i><strong class="ct_mm_hnum" id="ct_mm_hnum">' + comment[1] + "</strong> <span>&nbsp;·&nbsp;0评论</span>&nbsp;·&nbsp;<span>" + comment[2] + "</span> </a> </div> </div>";
                        var m = document.getElementsByClassName("ct_mm_hoard");
                        m.length > 0 && (m[0].onclick = function (t) {
                            comment[1] = 1, that.setCache(localCommentCacheName, comment.join("{$0}")), document.getElementById("ct_mm_hnum").innerHTML = 1;
                        });
                    }
                };
                loadComment();
                var publish = document.getElementById("publish");
                publish && (publish.onclick = function () {
                    if (that.getCache(localCommentCacheName)) return void alert("评论过于频繁，请稍后重试！");
                    var t = document.getElementById("txt1");
                    if (!t.value) return alert("请输入评论内容"), void t.focus();
                    that.setCache(localCommentCacheName, t.value + "{$0}0{$0}" + function () {
                        var t = new Date(), m = t.getFullYear(), e = t.getMonth() + 1, n = t.getDate(),
                            i = t.getHours(), c = t.getMinutes(), a = t.getSeconds();
                        return e < 10 && (e = "0" + e), n < 10 && (n = "0" + n), i < 10 && (i = "0" + i),
                        c < 10 && (c = "0" + c), a < 10 && (a = "0" + a), m + "-" + e + "-" + n + " " + i + ":" + c + ":" + a;
                    }()), alert("评论成功"), loadComment();
                });
            }
        },
        initialize: function (obj) {
            var scripts = document.scripts;
            for (var i = 0; i < scripts.length; i++) {
                if (this.cloudId == scripts[i].id) {
                    this.companyId = scripts[i].getAttribute('sid');
                    this.domain = scripts[i].src.replace("cloud/san_cloud.js", "sanCloud");
                    break;
                }
            }
            var param = 'companyId=' + this.companyId
                + '&vid=' + this.getBdVid()
                + '&pages=' + this.getPages()
                + '&width=' + this.getWidth()
                + '&height=' + this.getHeight()
                + '&device=' + this.getDeviceName()
                + '&language=' + this.getLanguage()
                + '&platform=' + this.getPlatform()
                + '&userAgent=' + this.getUserAgent()
                + '&colordepth=' + this.getColorDepth()
                + '&word=' + encodeURIComponent(this.getWord())
                + '&href=' + encodeURIComponent(this.getHref())
                + '&referrer=' + encodeURIComponent(this.getReferrer())
                + '&e_keywordld=' + this.getKeywordId()
                + '&dev=' + this.getDevice();
                this.pm=param
            this.getWecatData(param);
            this.setListenerCopy(param);
            this.setListenerComment();
        },
    };
    _cloudBase.initialize();
})();
